package com.youhome.clients.controller;

import com.youhome.common.exception.CustomException;
import com.youhome.common.response.Result;
import com.youhome.common.response.ResultCode;
import com.youhome.service.service.SMSService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by chen365 on 2017/7/17.
 */

@RestController
@Api(tags = "短信")
public class SMSController {

    @Autowired
    private SMSService smsService;

    /**
     * 获取验证短信
     *
     * @param type  活动标示 注册：register，忘记密码:forgetpassword
     * @param phone 手机号
     * @return
     */
    @ApiOperation(value = "获取验证短信", notes = "获取验证短信 ")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "String", name = "type", value = "短信类型 register(注册),login(登陆),client(客户)", required = true, paramType = "path"),
            @ApiImplicitParam(dataType = "String", name = "phone", value = "手机号", required = true, paramType = "path"),
            @ApiImplicitParam(dataType = "String", name = "shareId", value = "shareId", required = false, paramType = "query")
    })
    @GetMapping(value = "/sms/code/{type}/{phone}")
    public Object getSMS(@PathVariable String type,
                         @PathVariable String phone, String shareId) throws CustomException {
        return new Result(ResultCode.SUCCESS, smsService.getSMSCode(type, phone, shareId));
    }
}
